/**
 * Created by Brant on 2016/12/28.
 */
module.exports = function ($http,$q,httpservice) {
    var newsService = {};


    /**
     * 查询动态消息
     * @param sendUserId
     * @param receiveuserid 登录ID
     * @param itemid
     * @param pageNum 第几页
     * @param pageSize 每页显示条数
     * @returns {Promise}
     */
    newsService.queryMessage = function (sendUserId, receiveuserid, itemid, pageNum, pageSize) {
        var params = {
            "senduserid": sendUserId,
            "receiveuserid": receiveuserid,
            "itemid": itemid,
            "pageNum": pageNum,
            "pageSize": pageSize
        };
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.DynamicMessageUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    /**
     * 接受消息与拒绝消息
     * @param id 消息ID
     * @param status 状态 3-接受；5-拒绝
     * @param userName 用户名
     * @returns {Promise}
     */
    newsService.acceptOrRejectMsg = function (id, status, userName) {
        var params = {"id": id, "status": status, "userName": userName};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.receiveMessageUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    /**
     * 系统消息
     * @param userid 登录ID
     * @param pageNum 第几页
     * @param pageSize 每页显示条数
     * @returns {Promise}
     * @constructor
     */
    newsService.SystemMsg = function (userid, pageNum, pageSize) {
        var params = {"userid": userid, "pageNum": pageNum, "pageSize": pageSize};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.SystemMessageUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /**
     * 获取任务详情
     * @param taskId 任务Id
     * @returns {Promise}
     */
    newsService.getTaskDetail = function (taskId) {
        var params={"taskId":taskId};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.getJCDetailUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /**
     * 获取证据详情
     * @param evidenceID 证据id
     * @returns {Promise}
     */
    newsService.getEvidenceDetail = function (evidenceID) {
        var params={"id":evidenceID};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getEDetailUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /**
     * 获取证据详情的评论
     * @param evidenceId
     * @returns {Promise}
     */
    newsService.getCommentDetail = function (evidenceId) {
        var params={"evidenceId":evidenceId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getECommentUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /**
     * 获取证据详情的日志
     * @param evidenceId
     * @returns {Promise}
     */
    newsService.getLogDetail = function (evidenceId) {
        var params={"evidenceId":evidenceId};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.getELogUrl,
            params:params,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    /*证据分组*/
    newsService.getEvidenceTypeList = function () {
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.getETypeUrl,
            headers : {'Content-Type':'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    /**
     * 系统消息点击查看日程详情
     * @param userid 登录ID
     * @param pageNum 第几页
     * @param pageSize 每页显示条数
     * @returns {Promise}
     * @constructor
     */
    newsService.getWorksCheduleDetail = function (workScheduleId) {
        var params = {"workScheduleId": workScheduleId};
        var deferred = $q.defer();
        $http({
            method: 'GET',
            url: httpservice.getWorksCheduleDetailUrl,
            params: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };


    /**
     * 系统消息点击修改已读状态
     * @param messageid 消息ID
     * @param status 消息状态：1-未读；3-已读；9-已删除
     * @returns {Promise}
     */
    newsService.updateSysMessageStatus = function (messageid,status) {
        var params = {"messageid": messageid,"status":status};
        var deferred = $q.defer();
        $http({
            method: 'POST',
            url: httpservice.updateSysMessageStatusUrl,
            data: params,
            headers: {'Content-Type': 'application/json'}
        }).then(function successCallback(response) {
            deferred.resolve(response.data);
        }, function errorCallback(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

    return newsService;
};
